const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

// const formatTime = function(date) {
//   const year = date.getFullYear()
//   const month = date.getMonth() + 1
//   const day = date.getDate()
//   const hour = date.getHours()
//   const minute = date.getMinutes()
//   const second = date.getSeconds()

//   return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
// }

// n=2, 但是要求显示的数字必须为两位数,  
const formatNumber = n => {
  n = n.toString() // n='2'
  if (n[1]) {
    return n;
  }else {
    return `0${n}`
  }
  // return n[1] ? n : `0${n}` // n[0]=2, n[1]=null, 因此返回'02'
}

module.exports = {
  formatTime, formatNumber
}
